Repository navigation
[Draft, stacked on #2611] Add the OpenTelemetry tracing plugin (Execution and Invocation views) - #2612
Draft
normj wants to merge 9 commits into
Draft
[Draft, stacked on #2611] Add the OpenTelemetry tracing plugin (Execution and Invocation views)#2612normj wants to merge 9 commits into
normj wants to merge 9 commits into
Conversation
This was referenced Nov 18, 2026
normj
force-pushed
the
normj/durable-otel-package
branch
from
November 18, 2026 23:42
86cefdb to
af349e8
Compare
New package Amazon.Lambda.DurableExecution.OpenTelemetry. It is a plugin for the instrumentation plugin API and emits Workflow, Invocation, operation and attempt spans through System.Diagnostics.ActivitySource, so it takes no OpenTelemetry NuGet dependency. Every invocation of an execution joins one trace, anchored at the propagated remote parent or, without one, at a synthetic root derived from the execution ARN. The Workflow span, the synthetic root and the first segment of each operation have ids derived from the ARN, as in the JavaScript, Python and Java SDKs. Activity cannot set its own span id through its public API, so the ids are written to its private fields with UnsafeAccessor; that switches itself off if a runtime changes the fields, and a test notices. Also: sampling follows the upstream decision, waits/invokes/callbacks that finished while suspended are exported once, replayed steps link their first segment, the plugin supplies the chained-invoke trace header, adds log scope fields, and calls an application-supplied flush at the end of each invocation. The Execution view is not implemented yet. The package is part of the AOT publish check.
Adds the project to autover.json and a change file for its first release.
Covers the bug found by tracing a real execution: a step resumed after a retry was reported as a fresh start and got the derived id of its first segment a second time. Merged in the core fix (a resumed operation is a replay at start). The new tests run a step through three invocations and call the plugin hooks for a resumed step.
In this view operations are children of the Workflow span and link the Invocation. An operation has one span, with a derived id, exported by the invocation where it finishes, using the start and end times the service recorded. While it is open only its identity exists, so nothing is left unended when an invocation suspends. Reaching a finished operation by replay exports nothing, and a wait, invoke or callback that completed while suspended is exported once. Attempts are real spans in the invocation that ran them, parented on the operation's derived id before its own span exists. A parent starts no later than its earliest child. Application spans started inside the workflow, a child context or a step parent onto the Workflow, the child context or the attempt: the first two have no span yet, so a stand-in activity that carries their derived id is current. It is not created by an ActivitySource, so no listener sees it. The state both views share (trace context, Invocation span, Workflow span, synthetic root, sampling, propagation, log scope, flush) moved into a base class. OtelView.Execution no longer throws.
…st attempts Observed on a deployed function: the service resets a step's start time when it schedules a retry, and a later invocation cannot see an earlier attempt, so the Execution view's operation span can start after the attempts it parents.
…it is only replayed The shared conformance case 10 (and 17) expects one span for a completed submitter step that later invocations replay. The Python SDK gives finished operations no start hook on replay; this matches it.
ContextExtractors.W3C reads InvocationInfo.TraceParent, which comes from ILambdaContext.W3C (clientContext.w3c).
normj
force-pushed
the
normj/durable-otel-package
branch
from
November 19, 2026 00:07
af349e8 to
4865380
Compare
Only XRay, W3C and the tests call them. The extractors stay public.
Previously each span went through the application's sampler, so a sampler that ignores the parent (AlwaysOn) exported every operation span of an unsampled execution but not its Workflow span. Now the plugin starts no span when the decision is not to sample: an upstream decision is authoritative, and without one the Invocation span's sampling result decides for the rest. This matches the JavaScript, Python and Java SDKs, which wrap the sampler.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
Draft, stacked on #2611. The base branch is the plugin API branch of #2611, so this diff shows only the OpenTelemetry package. It should be retargeted to
masteronce #2611 merges.What this adds
A new package,
Amazon.Lambda.DurableExecution.OpenTelemetry, that is a plugin for the instrumentation plugin API of #2611. It has both views: Execution (the default) and Invocation.It emits
Workflow,Invocation, operation and attempt spans throughSystem.Diagnostics.ActivitySource, so the package has no OpenTelemetry NuGet dependency. The OpenTelemetry SDK, the ADOT layer andOpenTelemetry.Instrumentation.AWSLambdalisten to the source once the application addsOtelPlugin.ActivitySourceName.See the package README for the trace structure, attributes, sampling and options. It follows the JavaScript, Python and Java OTel plugins: one trace per execution anchored at the propagated remote parent or a synthetic root, derived ids for the Workflow span, the synthetic root and the first segment of each operation, upstream sampling decisions honored, and the chained-invoke trace header supplied to the SDK.
The two views
Execution(default)Workflow -> operation -> attemptInvocationInvocation -> operation -> attemptBoth exist in the JavaScript, Python and Java SDKs, with the same shape, and the shared conformance suite has an
otel-executionand anotel-invocationsuite.In the Execution view an operation has one span, with a derived id, exported by the invocation where it finishes using the start and end times the service recorded. While it is open only its identity exists, so nothing is left unended when an invocation suspends. Replaying a finished operation exports nothing. Attempts are real spans in the invocation that ran them, parented on the operation's derived id before its own span exists. Application spans started inside the workflow, a child context or a step parent onto the Workflow, the child context or the attempt through a stand-in
Activitythat carries the derived id and is never exported (it is not created by anActivitySource).Both views share one base class: trace context, Invocation span, Workflow span, synthetic root, sampling, propagation, log scope and flush.
The part to review closely: deterministic span ids
An execution runs as several invocations and nothing is stored between them, so a span exported by one invocation must name spans exported by another (the Workflow span, the link from a retried step's later segments to its first segment). That needs spans with chosen ids.
Activityhas no public way to set its own span id.The plugin writes the private
_spanIdand_idfields through[UnsafeAccessor](ActivityIdOverride), only for those spans. It is generated at compile time and passes the AOT publish check. The fields are not a contract, so:I checked it on net8.0 and net10.0 with the real OpenTelemetry SDK in a scratch project (not in this PR), including parent/child ids and a sampler following the parent flags. If you would rather not depend on private fields, the alternative is random ids plus a spec exception for cross-invocation references.
Found by the conformance tests (#2615)
In the Invocation view, a later invocation that only replayed a finished step or child context exported it again as a new segment. Now only an operation that had not finished when the invocation reached it (a retried step, a suspended context) gets a new segment; a finished one is exported once. This matches the Python SDK, and shared conformance cases 10 and 17 require it. The test that covered the old behavior now asserts the new one, and fails with the fix reverted.
W3C traceparent
ContextExtractors.W3Canchors the execution on a W3Ctraceparentinstead of an X-Ray header. The value comes fromILambdaContext.W3C(clientContext.w3c), which the Lambda team confirmed is where it is carried; #2611 exposes it asInvocationInfo.TraceParent. The default extractor is still X-Ray. Unit tests cover the parser; it has not been exercised against a deployed function.Not in this PR
[DurableExecution(Tracing = ..., PluginProvider = ...)]for Annotations: Add Tracing and PluginProvider options to [DurableExecution] #2614.Testing
68 tests on net8.0 and net10.0, using a plain
ActivityListener(no OpenTelemetry SDK) and the in-memory test runner from #2611, plus direct hook tests for cases the in-memory service cannot produce. They cover the span tree and parenting, derived ids, links and replay, a synthetic root, sampling, errors and statuses, completions while suspended, propagation, log scope, flush,Activity.Currenthandling, the exclusive group, and theActivityfield override. I broke the code on purpose in several places (no derived ids,Activity.Currentleaking, re-exported completions, override disabled, Workflow exported on every invocation) and the tests caught each one. The package is part of the Native AOT publish smoke test, which publishes with no IL warnings.Checked against a real durable execution (us-west-2)
I ran both views in a deployed function (a retried step, a wait, a child context, a parallel, a chained invoke, and a callback) with an in-process listener that prints each exported span, and active tracing on.
Invocation view, five invocations: one trace of 27 spans (this run predates the replay fix above, so some of those were re-exported finished steps). No duplicate span ids, every link resolves, each
Invocationspan's parent is the X-Ray function segment of its own invocation, andWorkflowis exported once. The retried step has three segments with distinct ids, and replayed ones link the first segment. The chained-invoke header lands on the right span: in X-Ray the invoked function'sAWS::Lambdasegments haveparent_idequal to the id of thecall_childspan. WithSampled=0upstream nothing is exported and the workflow succeeds.Execution view, four invocations: one trace of 20 spans, one span per operation:
No duplicate ids, every link resolves, replayed operations were not exported again, and the wait, the child context, the parallel and the invoke each have the service's start and end (the wait is 2000 ms, as configured).
Two real findings:
Not checked here: Lambda Managed Instances, or running the Native AOT binary. #2615 runs the plugin with the OpenTelemetry SDK's OTLP exporter and the ADOT collector layer.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.